home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / reuse.lha / reuse / c / MemoryDrv.c < prev    next >
C/C++ Source or Header  |  1992-08-18  |  3KB  |  124 lines

  1. /* $Id: MemoryDrv.c,v 1.6 1992/05/05 13:19:05 grosch rel $ */
  2.  
  3. /* $Log: MemoryDrv.c,v $
  4.  * Revision 1.6  1992/05/05  13:19:05  grosch
  5.  * added rcsid
  6.  *
  7.  * Revision 1.5  1991/11/21  14:28:16  grosch
  8.  * new version of RCS on SPARC
  9.  *
  10.  * Revision 1.4  91/01/21  12:13:23  grosch
  11.  * some performance improvements
  12.  * 
  13.  * Revision 1.3  90/09/20  09:12:24  grosch
  14.  * calmed down lint
  15.  * 
  16.  * Revision 1.2  90/09/04  17:32:12  grosch
  17.  * automatic determination of alignment
  18.  * 
  19.  * Revision 1.1  90/07/04  14:34:01  grosch
  20.  * introduced conditional include
  21.  * 
  22.  * Revision 1.0  88/10/04  11:44:43  grosch
  23.  * Initial revision
  24.  * 
  25.  */
  26.  
  27. /* Ich, Doktor Josef Grosch, Informatiker, Sept. 1987 */
  28.  
  29. static char rcsid [] = "$Id: MemoryDrv.c,v 1.6 1992/05/05 13:19:05 grosch rel $";
  30.  
  31. # include "ratc.h"
  32. # include "Memory.h"
  33. # include <stdio.h>
  34.  
  35. static    char        * p1, * p2, * p3, * p4;
  36. static    unsigned long    i;
  37. static    unsigned long    small, best, notbest, large;
  38.  
  39. char * AllocPrint (n)
  40.    unsigned long    n;
  41.    {
  42.       char *    a = Alloc (n);
  43.  
  44.       (void) printf ("Alloc:  n = ");
  45.       (void) printf ("%10ld", n);
  46.       (void) printf (", ADR = ");
  47.       (void) printf ("%8lx\n", a);
  48.       return a;
  49.    }
  50.  
  51. main ()
  52. {
  53.    InitMemory ();
  54.  
  55.    for (i = 0; i <= 62; i ++) {
  56.       p1 = AllocPrint (i);
  57.       p2 = AllocPrint (i);
  58.       Free (i, p1);
  59.       Free (i, p2);
  60.       p3 = AllocPrint (i);
  61.       p4 = AllocPrint (i);
  62.  
  63.       if (p3 != p2) {
  64.      (void) printf ("Alloc/Free small not inverse ");
  65.      (void) printf ("%10ld\n", i);
  66.       }
  67.  
  68.       if (p4 != p1) {
  69.      (void) printf ("Alloc/Free small not inverse ");
  70.      (void) printf ("%10ld\n", i);
  71.       }
  72.    }
  73.  
  74.    small    = 80;
  75.    best        = 96;
  76.    notbest    = 112;
  77.    large    = 128;
  78.  
  79.    for (;;) {
  80.       for (i = 7; i <= 24 /* 32 */; i ++) {
  81.      (void) printf ("        i = ");
  82.      (void) printf ("%10ld\n", i);
  83.  
  84.      p1 = AllocPrint (small);
  85.      p2 = AllocPrint (best);
  86.      p3 = AllocPrint (notbest);
  87.      p4 = AllocPrint (large);
  88.  
  89.      if (p1 == NULL || p2 == NULL || p3 == NULL || p4 == NULL) {
  90.         (void) printf ("\nMemory used: %10d\n", MemoryUsed);
  91.         return 0;
  92.      }
  93.  
  94.      Free (large    , p4);
  95.      Free (notbest    , p3);
  96.      Free (best    , p2);
  97.      Free (small    , p1);
  98.  
  99.      p1 = AllocPrint (best);
  100.      if (p1 != p2) {
  101.         (void) printf ("Alloc/Free large not inverse ");
  102.         (void) printf ("%10ld\n", i);
  103.      }
  104.  
  105.      p1 = AllocPrint (best);
  106.      if (p1 != p3) {
  107.         (void) printf ("Alloc/Free large not inverse ");
  108.         (void) printf ("%10ld\n", i);
  109.      }
  110.  
  111.      p1 = AllocPrint (best);
  112.      if (p1 != p4) {
  113.         (void) printf ("Alloc/Free large not inverse ");
  114.         (void) printf ("%10ld\n", i);
  115.      }
  116.       
  117.      small   += small;
  118.      best    += best;
  119.      notbest += notbest;
  120.      large   += large;
  121.       }
  122.    }
  123. }
  124.